widget: Add docs for ::measure
authorTimm Bäder <mail@baedert.org>
Sat, 22 Oct 2016 19:40:04 +0000 (21:40 +0200)
committerTimm Bäder <mail@baedert.org>
Sat, 22 Oct 2016 19:40:04 +0000 (21:40 +0200)
docs/reference/gtk/gtk4-sections.txt
docs/reference/gtk/migrating-3to4.xml
gtk/gtksizerequest.c
gtk/gtkwidget.h

index 7a36a2d488c0102a1148fc3e6c89e07b5131e3b5..fcd5ebdc6dd3b1b29581dc35a787c77cf33296fd 100644 (file)
@@ -4920,6 +4920,7 @@ gtk_widget_get_opacity
 gtk_widget_set_opacity
 gtk_widget_list_action_prefixes
 gtk_widget_get_action_group
+gtk_widget_measure
 
 <SUBSECTION>
 gtk_widget_get_path
index d45b688a7c67dd2ce34bfcc90ac6e0925d72ff29..e8ce306112f8c1591999a0e5805cd837d8024c61 100644 (file)
       </para>
     </section>
 
+    <section>
+      <title>Adapt to GtkWidget's size request changes</title>
+      <para>
+        GTK+3 used five different virtual functions in GtkWidget to
+        implement size requisition, namely the gtk_widget_get_preferred_width()
+        family of functions. To simplify widget implementations, GTK+4 uses
+        only one virtual function, GtkWidgetClass::measure() that widgets
+        have to implement.
+      </para>
+    </section>
+
   </section>
 
 </chapter>
index d80e47f4feb2a7fe3dc5255e5941a1df5905ede2..c030d0c90ae579ec942e45f9af56f43ee11d6d96 100644 (file)
@@ -808,6 +808,29 @@ gtk_distribute_natural_allocation (gint              extra_space,
   return extra_space;
 }
 
+/**
+ * gtk_widget_measure:
+ * @widget: A #GtkWidget instance
+ * @orientation: the orientation to measure
+ * @for_size: Size for the opposite of @orientation, i.e.
+ *   if @orientation is %GTK_ORIENTATION_HORIZONTAL, this is
+ *   the height the widget should be measured with. The %GTK_ORIENTATION_VERTICAL
+ *   case is analogous. This way, both height-for-width and width-for-height
+ *   requests can be implemented. If no size is known, -1 can be passed.
+ * @minimum: (out) (optional): location to store the minimum size, or %NULL
+ * @natural: (out) (optional): location to store the natural size, or %NULL
+ * @minimum_baseline: (out) (optional): location to store the baseline
+ *   position for the minimum size, or %NULL
+ * @natural_baseline: (out) (optional): location to store the baseline
+ *   position for the natural size, or %NULL
+ *
+ * Measures @widget in the orientation @orientation and for the given @for_size.
+ * As an example, if @orientation is GTK_ORIENTATION_HORIZONTAL and @for_size is 300,
+ * this functions will compute the minimum and natural width of @widget if
+ * it is allocated at a height of 300 pixels.
+ *
+ * Since: 3.90
+ */
 void
 gtk_widget_measure (GtkWidget      *widget,
                     GtkOrientation  orientation,
@@ -819,6 +842,8 @@ gtk_widget_measure (GtkWidget      *widget,
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (for_size >= -1);
+  g_return_if_fail (orientation == GTK_ORIENTATION_HORIZONTAL ||
+                    orientation == GTK_ORIENTATION_VERTICAL);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
index d032582932fc00e005d1b6e2e364b16100cff840..bb09211f0e13306667e0f45223c8b1e2e22ae599 100644 (file)
@@ -199,30 +199,10 @@ struct _GtkWidget
  *   to both of the virtual methods #GtkWidgetClass.get_preferred_height_for_width()
  *   and #GtkWidgetClass.get_preferred_width_for_height() since it might be 
  *   queried in either #GtkSizeRequestMode by its parent container.
- * @get_preferred_height: This is called by containers to obtain the minimum
- *   and natural height of a widget. A widget that does not actually trade
- *   any height for width or width for height only has to implement these
- *   two virtual methods (#GtkWidgetClass.get_preferred_width() and
- *   #GtkWidgetClass.get_preferred_height()).
- * @get_preferred_width_for_height: This is analogous to
- *   #GtkWidgetClass.get_preferred_height_for_width() except that it
- *   operates in the oposite orientation. It’s rare that a widget actually
- *   does %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT requests but this can happen
- *   when, for example, a widget or container gets additional columns to
- *   compensate for a smaller allocated height.
- * @get_preferred_width: This is called by containers to obtain the minimum
- *   and natural width of a widget. A widget will never be allocated a width
- *   less than its minimum and will only ever be allocated a width greater
- *   than the natural width once all of the said widget’s siblings have
- *   received their natural widths.
- *   Furthermore, a widget will only ever be allocated a width greater than
- *   its natural width if it was configured to receive extra expand space
- *   from its parent container.
- * @get_preferred_height_for_width: This is similar to
- *   #GtkWidgetClass.get_preferred_height() except that it is passed a
- *   contextual width to request height for. By implementing this virtual
- *   method it is possible for a #GtkLabel to tell its parent how much height
- *   would be required if the label were to be allocated a said width.
+ * @measure: This is called by containers to obtain the minimum and natural
+ *   size of the widget. Depending on the orientation parameter, the passed
+ *   for_size can be interpreted as width or height. A widget will never be
+ *   allocated less than its minimum size.
  * @mnemonic_activate: Activates the @widget if @group_cycling is
  *   %FALSE, and just grabs the focus if @group_cycling is %TRUE.
  * @grab_focus: Causes @widget to have the keyboard focus for the